package cn.caskm.souvenirshopsystem.controller.api;

import cn.caskm.souvenirshopsystem.domain.Result;
import cn.caskm.souvenirshopsystem.domain.dto.AddOrRemoveCartDTO;
import cn.caskm.souvenirshopsystem.domain.vo.ShopCartVO;
import cn.caskm.souvenirshopsystem.service.ShoppingCartService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shopCat")
@RequiredArgsConstructor
public class ShopCatController {

    private final ShoppingCartService shoppingCartService;

    @GetMapping("/listCart")
    public Result<List<ShopCartVO>> listCart() {
        return shoppingCartService.listCart();
    }

    @PostMapping("/addOrRemoveGoodsToCart")
    public Result<Object> addOrRemoveGoodsToCart(@RequestBody AddOrRemoveCartDTO body) {
        shoppingCartService.addOrRemoveGoodsToCart(body.getGoodsId(), body.getIfAdd());
        return Result.success();
    }

    @PutMapping("/updateAllCheckStatus")
    public Result<Object> updateAllCheckStatus(@RequestParam("flag") Boolean flag) {
        shoppingCartService.updateAllCheckStatus(flag);
        return Result.success();
    }

    @DeleteMapping("/delete/{goodsIds}")
    public Result<Object> deleteCart(@PathVariable("goodsIds")List<Integer> goodsIds) {
        shoppingCartService.deleteCart(goodsIds);
        return Result.success();
    }

}
